home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
libs
/
knowhow4
/
example.doc
< prev
next >
Wrap
Text File
|
1994-05-30
|
32KB
|
841 lines
To know more about working in KNOW-HOW lets construct few examples.
1. Blocks. The most simple way of adding complex mouse support
to you objects is to use ObjectKit class and its derivatives. This
class itself is a container for Visible derivatives, and at the
same time a Visible's child:
class Kit : public Visible
....
class ObjectKit : public Kit
{
Visible** list;
....
}
First block class - Bl - is the ObjectKit child, whose constructor
add to its list the base Window and Element for CANCEL operation.
Next class - Block - have also PGUP, PGDN, LEFT, RIGHT and so on
buttons.
Now lets use Write class (simple text editor) to produce
text editor with buttons (BLKWRITE file).
#include "write.h" // Write class
#include "blk.h" // Block class
class BlockWrite : public Block
{
public:
Write* write; // Attention! It is good idea to make it public.
BlockWrite(rect coord, // Window coordinates (rect defined in GEOM.H)
char* fname = "", // Swap file name, used ONLY if no upper
// level container is used.
char* fileName = "work.txt", // Text file to edit
char* h = "", // Window header
int s = 0, // Shadow width, pixels
int res = 0, // See Visible.h
BORDERS b_type = SHOW_BORDER, // See Carcase.h
BORDERS write_border = SHOW_BORDER, // See Carcase.h
BORDERS hdr_b_type = SHOW_BORDER, // See Carcase.h
int pat = 0, // Edit field pattern
int write_pat = 0, // Pen color
int hdr_pat = 0, // Header fill pattern
int elem_pat = 0); // Buttons fill pattern
virtual void rearrange(); // After changing of size of the base
// window, you should call this function
// which will change coordinates of other
// objects.
virtual void hide(); // Remove from screen and maybe any other
// functions (like SAVE - Y/N querry)
};
Write* become data member of block class, and we define constructor
to initialize it. Remember that if you put pointer to container,
no further call to delete is necessary. Object's destructor will
delete all the objects belonging to it.
Constructor:
BlockWrite::BlockWrite(rect coord, char* fname, char* fileName,
char* h, int s, int res, BORDERS b_type, BORDERS write_border,
BORDERS hdr_b_type, int pat, int write_pat, int hdr_pat,
int elem_pat)
: Block(coord, fname, h, s, res, b_type, hdr_b_type, pat, hdr_pat,
elem_pat)
{
rect r = textRect(w1->bound()); // Get size of base window.
r.origin.Y += 2;
r.corner.Y -= (1 + textY(s));
r.origin.X += 3;
r.corner.X -= (3 + textX(s));
Construct text editor:
write = new Write(r, fileName, "", "", 0, write_border, NO_BORDER,
write_pat, 0);
The following function will modify "ret" flag of this object. This
result to the changes in its behaviour. If we leave Write - we'll leave
container to.
write->set_ret(1);
Put object to container. Write object becomes first, this mean that it
will have control when Block becomes active.
insert(write, 1);
Now we need to link buttons, write object, and actions. For example, if
LEFT button is pressed, write object become active and get message AC_LEFT.
It will process message and return control to the button (if it is CANCEL
button, block will loose the control - see BL.H and SCI discussion above).
assign(write, left_element, AC_LEFT);
assign(write, right_element, AC_RIGHT);
assign(write, up_element, AC_UP);
assign(write, dn_element, AC_DOWN);
assign(write, cancel_element, AC_CANCEL);
assign(write, pg_up_element, AC_PG_UP);
assign(write, pg_dn_element, AC_PG_DN);
}
rearrange() function use new coordinates of base window to resize other
objects in container.
void BlockWrite::rearrange()
{
Block::rearrange(); // Base window and buttons
rect r = textRect(w1->bound()); // Get size
int s = w1->get_shadow();
r.origin.Y += 2;
r.corner.Y -= (1 + textY(s));
r.origin.X += 3;
r.corner.X -= (3 + textX(s));
write->repose(r); // Change coordinates of write object.
}
Hide object is necessary to explicitely call write->hide(). The reason
is that editor removes itself from memory when it is not in use.
void BlockWrite::hide()
{
write->hide();
w1->hide();
}
2. Second example. Non-container classes.
KNOW-HOW.SLANG is the (window-independent) basic-like language.
As the example KNOW-HOW include the derivative KNOW-HOW.SLANG.DRAW. Base
Slang was overloaded and BGI-specific functions becomes available. This
class is called OOPic (Object-Oriented Pictures ? Sorry, try something
better if you do not like it).
Now lets write the program which use OOPic to draw pictures in the window.
#include "window.h"
#include "oopic.h"
class KH_OOPic : public OOPic, public Window
{
public:
KH_OOPic(rect coordinates) : OOPic(), Window(coordinates) {}
virtual void show(); // All drawing, including program execution.
virtual void exe(int act = 0); // User interface
};
The constructor initialize window and interpreter. The show() function
draws window and then run OOPic program.
The exe() function is of special interest. If we want to support some
dialog with user we should process corresponding events.
void KH_OOPic::show()
{
Window::show(); // Show window
if(program != NULL) // If program is loaded
{
rect r = user_screen(); // Set clip area
setviewport(r.origin.X, r.origin.Y, r.corner.X, r.corner.Y, 1);
basic(program); // Run program
setviewport(0, 0, getmaxx(), getmaxy(), 1); // Restore clip area
}
}
///////////////////
void KH_OOPic::exe(int act)
{
e.what = act ? KEYEVENT : NOEVENT; // act or user input
switch(act) // Messages are replaced by keyboard events. Trick.
{
case AC_LEFT: e.key = EVENT_LEFT; break;
case AC_RIGHT: e.key = EVENT_RIGHT; break;
case AC_UP: e.key = EVENT_UP; break;
case AC_DOWN: e.key = EVENT_DN; break;
case AC_PG_UP: e.key = EVENT_PG_UP; break;
case AC_PG_DN: e.key = EVENT_PG_DN; break;
case AC_CTRL_PG_UP: e.key = EVENT_CTRL_PG_UP; break;
case AC_CANCEL: e.key = (isRet(RET_REMOVE))
? EVENT_ALT_F3 : EVENT_ESC;
break;
case AC_OK: e.key = EVENT_F2; break;
}
mouseHideCursor();
if(!act)
hilite();
int on = 0;
mouseShowCursor();
rect r = user_screen();
while(1)
{
mouseShowCursor();
if(!act && !(e.what == MOUSEEVENT && !on)) // Get user-produced event
get_event(); // or process "act" message
else
on = 1;
mouseHideCursor();
if(e.what == KEYEVENT)
{
switch(e.key)
{
case EVENT_RIGHT: lt.X += 8; break;
case EVENT_LEFT: lt.X = lt.X < 8 ? 0 : lt.X - 8; break;
case EVENT_UP: lt.Y = lt.Y < 8 ? 0 : lt.Y - 8; break;
case EVENT_DN: lt.Y += 8; break;
case EVENT_HOME: lt.X = 0; break;
case EVENT_PG_UP:
lt.Y = lt.Y < r.height() ? 0 : r.height(); break;
case EVENT_END: lt.X += r.width(); break;
case EVENT_PG_DN: lt.Y += r.height(); break;
case EVENT_CTRL_PG_UP: lt.Y = 0; break;
Put your attention to the following messages. They made current class
compatible with other KNOW-HOW classes and messages exchange protocol.
case EVENT_F1: global_i[0] = action_type; return;
case EVENT_ESC: global_num = 0;
global_i[0] = AC_NULL; return;
case EVENT_F6:
case EVENT_F10:
case EVENT_TAB:
case EVENT_ALT_F3:
case EVENT_ALT_F4:
case EVENT_ALT_TAB:
unhilite(); global_num = 1;
global_i[0] = 0; return;
case EVENT_F2:
case EVENT_RETURN : unhilite(); global_num = 1;
global_i[0] = action_type; return;
}
if(program != NULL) // If program is loaded
{
clrscr();
setviewport(r.origin.X, r.origin.Y, r.corner.X, r.corner.Y, 1);
basic(program); // Run program
setviewport(0, 0, getmaxx(), getmaxy(), 1); // Restore clip area
}
}
else
{
if(!mouse_in(e.where())) // Mouse pressed outside
{
unhilite();
global_num = 0; global_i[0] = AC_NULL;
return;
}
}
if(act) // leave object and return to the object which calls it
{ // after single processing of "act" command
global_num = 1;
return;
}
}
}
Here is the example of usage of the KH_OOPic.
//////////////
void main()
{
if(!init_KNOW_HOW())
return;
setfillstyle(SOLID_FILL, pColorSet->colors.BAK_COLOR);
bar(0, 0, getmaxx(), getmaxy());
KH_OOPic s(rect(10, 0, 60, 24));
s.show();
s.set_program(s.load_program("work.bas"));
s.show();
s.exe();
close_KNOW_HOW();
closegraph();
}
3. Building the Application.
Now lets write the program which use KH_OOPic to draw pictures and Write
to edit programs. It also should print pictures using KNOW-HOW.Print with
any deformation.
WHAT WE NEED.
The menu tree of application would be designed in the following manner
("Nothing" means that it is demo example only):
File Edit Options Methods Scripts Print
| | | | | |
| | Nothing Nothing | PrintPanel
| | |
| | Play -->
| | KH_OOPic Record ->|
| | BlockWrite Stop -->|
| Nothing Macros ->|
| Edit -->|
| |
New |
Open ------------> F |
Save ------------> I <--------------------------
save Pcx --------> L
save pcx B&W ----> E
About system -------> Context specific action
|
Board
File VECTOR.H
VECTOR 1.0 - The vector images Editor.
(C) Stepan S. Vartanov, 1994.
ATTENTION !!! This product needs the KNOW-HOW 4.x interface library
and (desirable) KNOW-HOW 1.x PRINT MANAGER SYSTEM
All headers we need should be included here.
#include "khoopic.h" // khoopic.h or blkoopic.h could be used
#include "ask_hot.h" // Button which may be hidden and macros append
// function
#include "icon.h" // "About" cartoon film
#include "board.h" // "About" system
#include "prn_form.h" // Printer setup
#include "appkit.h" // ApplicationKit
#include "blkwrite.h" // write.h or blkwrite.h could be used
#include "print.h" // Print manager
#include "b&w.h" // PCX color <-> B&W convertor
#include "help.h" // Help system
#include "bllmenu.h" // Line (main) menu
#include "blkmenu.h" // Box menu
#include "blfsys.h" // File system
#include "window.h"
Registration of the "user-defined functions". When the program works,
different objects gets and losts control (focus of input in WINDOWS).
UDFunctions are called in this moment.
enum { AC_FILE_MENU = 101, AC_EDIT_MENU, // items of the line menu
AC_OPTIONS_MENU, AC_METHOD_MENU, AC_SCRIPT_MENU, AC_PRINT_MENU,
AC_NEW, AC_OPEN, AC_SAVE, AC_SAVE_AS_PCX, // go here from "file_menu"
AC_SAVE_AS_PCX_BW, AC_ABOUT,
AC_SCRIPT_PLAY, AC_SCRIPT_RECORD, // go here from "script_menu"
AC_SCRIPT_END, AC_MACROS_KEEP, AC_EDITOR,
AC_PROGRAM_EDIT, AC_PROGRAM_RUN, // Program editor and interpreter
AC_ASK_EXIT, // Before exit ask Y/N
AC_PRINT, // go here from "form" (print setup)
AC_MOVE_APPL, AC_RESIZE_APPL, // If you want to move / resize base
AC_FILE // After File system was executed
};
Class Vector. It include pointers to all its objects. The only reason
is possibility of calls for functions, which are not virtual members
of Visible class. If you do not need it - use ApplicationKit::list[i]
instead.
class Vector : public ApplicationKit
{
protected:
int DATA_FILE; // The way we come to the File system (f.e. from Open
// or Save).
Window* w1; // System base window
BlockLineMenu* menu; // Main menu
BlockMenu* file_menu; // New, Open, Save...
BlockFile* file_sys; // List of files
BlockMenu* script_menu; // Script Manager
PrintManager* print; // Print Manager
GrafBuffer* buffer; // Buffer of Print and PCX managers
Form* form; // Printer setup
Write* editor; // Text (program) editor
BlockWrite* script_editor; // Text (script) editor
KH_OOPic* vector; // Picture draw window.
public:
Vector(char* fileName, // File for swapping
char* buf_name, // Name of Print/PCX tmp. swap file
int obj_number = 0, // Number in upper level container
int step = 1); // Step in objects numeration.
virtual ~Vector(); // Destructor
virtual void show(); // Show some objects
// virtual void rearrange(); // Used if resize facility is available
virtual int application(int n); // User-defined functions
void prepare_files(); // Before file_system
virtual int active() { return w1->active(); } // Is visible?
};
#endif __VECTOR_H_
When you build application, you need to create 4 new files. Header (below)
is the first, and the other are:
VECTOR.CPP file. Contain constructor, show(), rearrange() and possible,
some service functions.
VECTAPPL.CPP file. application() function. Switch to call user-defined
functions.
VECTMAIN.CPP file. Contains main() function.
Lets construct this files together.
File VECTOR.CPP:
#include "vector.h" // We include header
int application(int) { return 0; } // Dummy function - will not be in use
// If user want use class (like Vector class), the Vector::application()
// overload it. If user use set of non-class functions (bad idea), it
// will be overloaded with non-class application().
rect r_draw_size; // == bound of draw object, expanded or not.
// Used in general for move and resize functions.
Vector::Vector(char* fileName, char* bufName, int obj_num, int step)
: ApplicationKit(step, loc(39, 13))
{
set_object_number(obj_num); // To use in upper-level container
DATA_FILE = 1;
// Constructors for objects
//////////////////////////////// Base Window
rect r_base(0, 0, 80, 25);
w1 = new Window(r_base, fileName, "", 0, BUTTON_BORDER, NO_BORDER,
MOVE | RESIZE, 0, 0);
//////////////////////////////// Interpreter
rect r_vector(0, 2, 40, 25);
vector = new KH_OOPic(r_vector);
////////////////////////////// Line Menu
rect r_menu(5, 0, 80, 2);
static char* hotMenuList = "FEOMSP"; // hot for line menu
static char* menuList[] = { " File", " Edit", " Options",
" Method", " Script", " Print", "" };
menu = new
BlockLineMenu(r_menu, "", hotMenuList, menuList, rect(0, 24, 79, 25),
0, NULL, NULL, BUTTON_BORDER, 16, 16, 16);
//////////////////////////////// Resize/Move object - menu with two icons.
// To be used with MOVE / RESIZE facilities
// rect r_resize_panel(0, 0, 5, 3);
// static int ic_resize_list[] = { I_MOVE, I_RESIZE, 0 };
// loc l = pScreenSet->g_mode == VGAHI ? loc(4, 4) : loc(4, 2);
// resize_panel = new IconMenu(r_resize_panel, "", "",
// NULL, 1, 1, SMALL_ICON, ic_resize_list, l,
// rect(0, 0, 25, 80), 0, NULL, NULL, FIXED, 0,
// BUTTON_BORDER, NO_BORDER);
//////////////////////////////// Script editor. Popup.
rect r_script_edit(10, 5, 70, 20);
script_editor = new
BlockWrite(r_script_edit, "", "work.txt", "Editor", 6,
MOVE | RESIZE, SHOW_BORDER, SHOW_BORDER, SHOW_BORDER,
0, 0, 0, 16);
////////////////////////// Program editor. Staked.
rect r_edit(40, 2, 80, 25); // Editor
editor = new Write(r_edit, "work.vec", "", "Editor", 6,
SHOW_BORDER, SHOW_BORDER, 0, 0);
////////////////////////// New - Open - Save - ... menu
rect r_file = rect(5, 3, 30, 16);
static char* hotFileList = "NOSPB?"; // hot for file menu
static char* fileList[] = { " New ", " Open ",
" Save", " save As pcx", "save as pcx B&w",
" << ? >> ", "" };
file_menu = new BlockMenu(r_file, "", " Files ", 6, hotFileList,
fileList, rect(0, 24, 79, 25), 0, NULL, NULL,
FIXED, SHOW_BORDER, SHOW_BORDER, 16, 16, 16, 16);
/////////////////////////// File list
file_sys = new BlockFile("File");
////////////////////////// Scripts menu
rect r_script = rect(50, 4, 69, 17);
static char* items_script[] = { " Play", " Record", " Stop", " Macros",
" Edit", "" };
static char* hotScriptList = "PRSME"; // for script menu
script_menu = new BlockMenu(r_script, "", " Scripts ", 6,
hotScriptList, items_script, rect(0, 24, 79, 25), 0, NULL, NULL,
FIXED, SHOW_BORDER, SHOW_BORDER, 16, 16, 16, 16);
///////////////////////////
r_draw_size = vector->user_screen();
///////////////////////////// Print system.
rect r = vector->user_screen();
r.corner.Y -= 1;
buffer = new GrafBuffer(loc(750, 550), bufName, r);
print = new PrintManager(EPSON9, DD, 1, rect(1, 1, 1, 1), 0,
PAPER_ON, 6);
form = new Form();
///////////////////////////
// We add objects to the container "kit". Order is significant.
background(w1);
add(menu);
add(vector);
add(editor);
// add(resize_panel); // MOVE and RESIZE the program kit
add(file_menu); // go here from "menu" FILE
add(file_menu); // go here from "menu" EDIT (really - not).
add(file_menu); // go here from "menu" OPTIONS
add(file_menu); // go here from "menu" METHODS
add(script_menu);
add(form);
add(file_sys); // go here from "file_menu", "script_menu"...
add(file_sys);
add(file_sys);
add(file_sys);
add(script_editor);
// We set the numbers (or the names, which may be transformed to number
// of the objects which will be called after exiting from current object
// with ENTER-like command.
// set_point(fill_prompt, fill_panel);
// we set, that after exiting from object with ENTER-like command it will
// call function N + no of menu choice - 1 from appl1.cpp file,
// and then call object No ... in list. Note that it can overwrite the
// set_point settings.
// assign(w1, resize_panel, AC_MOVE); // Reserved
assign(file_menu, menu, AC_FILE_MENU);
assign(file_sys, file_menu, AC_NEW); // ATTENTION!!! OPEN and SAVE
// points to the same file_sys object.
assign(file_sys, script_menu, AC_SCRIPT_PLAY);
assign(0, form, AC_PRINT);
assign(0, file_sys, AC_FILE);
assign(0, script_editor, AC_EDITOR);
assign(0, editor, AC_PROGRAM_RUN);
assign(editor, vector, AC_PROGRAM_EDIT);
set_exit(AC_ASK_EXIT);
// We can set the numbers (or the names, which may be transformed to number
// of the objects which will be called after exiting from current object
// with ESC-like command. If current object was called from another
// object, its callFrom flag will be changed, correspondingly, so it is not
// absolutely necessary : kit->set_call(file_menu, menu)...
// default object hides itself after exiting. But to obtain first-second-third...
// level menu cascade we must change return flag to 2. In this case menu
// will hide itself after exiting with ESC-like command, and will not -
// if the next menu must be called (ENTER command).
menu->set_ret(RET_CANCEL | RET_STACKED | RET_SHOW);
file_menu->set_ret(RET_MOUSE | RET_CANCEL | RET_TRANSFER);
form->set_ret(RET_MOUSE | RET_CANCEL | RET_OK);
script_menu->set_ret(RET_CANCEL | RET_MOUSE | RET_TRANSFER);
file_sys->set_ret(RET_CANCEL | RET_MOUSE | RET_TRANSFER);
script_editor->set_ret(RET_OK | RET_MOUSE | RET_CANCEL);
w1->set_ret(RET_STACKED);
// resize_panel->set_ret(RET_STACKED | RET_SHOW);
editor->set_ret(RET_STACKED | RET_SHOW);
vector->set_ret(RET_STACKED | RET_SHOW);
// Setting of the context help. ATTENTION!!! only ObjectKit childs have help.
menu->set_help_context("common ");
file_menu->set_help_context("file_sys");
script_menu->set_help_context("script ");
form->set_help_context("printset");
}
/////////////////////////////// Destructor.
Vector::~Vector()
{
editor->hide();
delete print;
delete buffer;
}
///////////////////////// We need to show only few objects.
void Vector::show()
{
mouseHideCursor();
WindowManager::show_window(w1);
vector->set_program(vector->load_program("work.vec"));
WindowManager::show_window(vector);
WindowManager::show_window(editor);
WindowManager::show_window(menu);
// WindowManager::show_window(resize_panel);
moveTo(1);
mouseShowCursor();
}
//////////////////////////
File VECTAPPL.CPP
Here is the simplified version of application(). It means that only
few options are available. This is for simplicity only, source codes of
library contain complete program.
#include "vector.h" // Vector class
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "global.h" // Global variables
#include <dos.h>
enum { SAVE = 1, DONT_SAVE }; // Picture status: changed or not.
This enumeration is used by file system. It keep the pre-history of call to
file_sys (F.e. from Open or Save)
enum { FILE_NEW = 30, FILE_OPEN, FILE_SAVE, FILE_SAVE_AS_PCX,
FILE_SAVE_AS_PCX_BW,
SCRIPT_PLAY, SCRIPT_RECORD, SCRIPT_END, MACROS_KEEP, TEXT_EDIT };
/////////////////////////////////////////////////////////////////////////////
//------> The following part is common for programs with SCRIPTS <---------\\
void file_refresh() // Used to get previous script name from stack
{ // Scripts and macroses could (with some
scriptMode = GO; // Limitations) be nested.
delete scriptFileName;
scriptFileName = NULL;
mac_status mac = macros_pop(); // Obtain previous status
delete mac.file;
}
//------> The above part is common for programs with SCRIPTS <-------\\
/////////////////////////////////////////////////////////////////////////////
// File preparing system. Not necessary but strongly reckomended.
void Vector::prepare_files()
{
delete global[1]; delete global[2];
global[1] = strdup("work"); global[2] = strdup("");
(file_sys->file_system)->setItems();
}
/////////////////////////////////////////////////////////////////////////////
// Board (window with PCX in it) is displayed and the simple movie is
// runned in it. Icons with few fazes of demo are showed one after another.
void about()
{
Board* board = new Board(rect(5, 5, 65, 20), "about.pcz",
"about.pcy", "A B O U T", 8, 0, 16);
board->show_window();
Icon i(loc(1, 1), 2, LARGE_ICON, SHOW_BORDER);
char* file = i.icon_open();
FILE *stream;
if((stream = fopen(file, "r+b")) == NULL)
return;
loc size = icon_size(LARGE_ICON);
int i_size = ((size.X + 1 + 7) >> 3 << 2) * (size.Y + 1) + sizeof(imageP);
imageP image = (imageP)malloc(i_size + 10);
while(1)
{
for(int j = 1; j < 9; j++)
{
get_image(stream, j, image, i_size);
putimage(screenXL(8), screenYT(8), image, COPY_PUT);
delay(20);
if(eventavail(KEYEVENT | MOUSEEVENT,
MCleftDn | MCrightDn))
break;
}
if(eventavail(KEYEVENT | MOUSEEVENT,
MCleftDn | MCrightDn))
break;
}
get_event();
fclose(stream);
delete image;
board->hide();
delete board;
}
/////////////////////////////////////////////////////////////////////////////
// User-defined functions. It is good idea to write all functions, even
// it they do nothing but only passes the control from one menu to another.
// To know more about this topic see discussion about Simplified User
// Interface in KNOW_HOW.TXT.
int Vector::application(int n)
{
rect r = vector->user_screen(); // If Block_KH_OOPic used, use
// (vector->vector->)user_screen()
loc mspos = e.where(); // Mouse position
sound(100); delay(100); nosound(); // I want some beeps
switch(n)
{
// case AC_MOVE: // We do not support MOVE and RESIZE
// global_i[0] = AC_MOVE; // in this simple application.
// return 0; // But it is not difficult to do.
// case AC_RESIZE: // Use KNOW-HOW.DRAW as the example.
// global_i[0] = AC_RESIZE;
// return 0;
case AC_FILE_MENU: // Go from line menu to the corresponding
case AC_SCRIPT_MENU: // objects. We only pass the control here.
return 2; // Call the next menu.
case AC_EDIT_MENU: // This 3 menu positions are temporarly
case AC_OPTIONS_MENU: // empty. You could develope this
case AC_METHOD_MENU: // application using them. But now they
return 0; // returns 0 - no action or control pass.
case AC_PRINT_MENU: // Pass the control to the Printer setup
return 2; // form.
case AC_PRINT: // Print to printer. To be changed.
return 1;
case AC_NEW: // Load empty program file.
editor->unload_file(); // See WRITE.H
editor->set_swap("noname.vec");
editor->set_header("noname.vec");
editor->show();
return 1; // Hide menu.
case AC_OPEN:
prepare_files(); // Prepare file list
(file_sys->edit)->put_string("*.vec"); // Set new file mask
DATA_FILE = FILE_OPEN; // Remember pre-history
return 2; // Call next object
case AC_SAVE:
prepare_files();
(file_sys->edit)->put_string("*.vec");
DATA_FILE = FILE_SAVE;
return 2;
case AC_SAVE_AS_PCX:
prepare_files();
(file_sys->edit)->put_string("*.pcx");
DATA_FILE = FILE_SAVE_AS_PCX;
return 2;
case AC_SAVE_AS_PCX_BW:
prepare_files();
(file_sys->edit)->put_string("*.pcx");
DATA_FILE = FILE_SAVE_AS_PCX_BW;
return 2;
case AC_ABOUT:
about();
return 1;
//------> The following part is common for programs with SCRIPTS <---------\\
case AC_SCRIPT_PLAY:
DATA_FILE = SCRIPT_PLAY;
prepare_files();
(file_sys->edit)->put_string("*.sc"); // set mask for file system
return 2;
case AC_SCRIPT_RECORD: // recording of script
prepare_files();
DATA_FILE = SCRIPT_RECORD;
(file_sys->edit)->put_string("*.sc");
return 2;
case AC_SCRIPT_END: // end of script recording.
DATA_FILE = SCRIPT_END;
file_refresh();
return 1;
case AC_MACROS_KEEP:
DATA_FILE = MACROS_KEEP;
if(scriptMode == PLAY)
{
scriptMode = GO;
return 1;
}
file_refresh();
prepare_files();
(file_sys->edit)->put_string("*.sc");
return 2;
//------> The above part is common for programs with SCRIPTS <-------\\
case AC_EDITOR:
DATA_FILE = TEXT_EDIT;
file_refresh();
prepare_files();
(file_sys->edit)->put_string("*.sc");
return 2;
case AC_PROGRAM_EDIT: // Editor and interpreter call
return 2; // one to another. But after
case AC_PROGRAM_RUN: // Interpreter we do nothing but
while(vector->play_used != 0) // pass control, and after editor
delete vector->playpop(); // we unload old version of the
// program,refresh system settings
delete vector->program; // and load new, edited program.
vector->error = 0;
vector->set_program(vector->load_program(editor->getFileName()));
vector->show();
return 0;
// Exit program.
case AC_ASK_EXIT:
return ask_exit(); // Return 0 or 1 and pass control as it is.
case AC_FILE: // Using DATA_FILE pre-history, work with
switch(DATA_FILE) // files.
{
case FILE_OPEN:
editor->unload_file();
editor->set_swap(global[global_i[1]]);
editor->set_header(global[global_i[1]]);
WindowManager::hide_window(); // Hide file_sys
WindowManager::hide_window(); // Hide file_menu
editor->show();
moveTo(get(editor));
return 0;
case FILE_SAVE:
editor->set_swap(global[global_i[1]]);
editor->set_header(global[global_i[1]]);
WindowManager::hide_window(); // Hide file_sys
WindowManager::hide_window(); // Hide file_menu
editor->swap();
editor->show();
moveTo(1);
return 0;
case AC_SAVE_AS_PCX: // To be changed
case AC_SAVE_AS_PCX_BW:
WindowManager::hide_window(); // Hide file_sys
WindowManager::hide_window(); // Hide file_menu
moveTo(1);
return 0;
default:
return 0;
}
}
}
//////////////////////
File VECTMAIN.CPP
#include <alloc.h> // The example of simple graphics editor interface
#include <iostream.h> // creation. The program shows linemenu with
#include <conio.h> // Paint Brush like choices: File, Edit, View etc.,
// Help system explains the behavior of package
#include "vector.h"
extern unsigned _stklen = 16000; // In some cases it is usefull
void main()
{
if(!init_KNOW_HOW(DETECT, 1)) // Initialization
return;
/////////////////////////// // Hypertext help system.
rect r_help(5, 5, 70, 25);
help_object = new HypertextView(r_help, "vector.hlp", "_help.pcy",
MOVE | RESIZE,
pScreenSet->sub_interval,
SHOW_BORDER, 10, "VECTOR",
BLUE, YELLOW, 56);
// Constructor
Vector* v = new Vector("vector.pcy", "work.buf");
// Show object
v->show();
// Run program
v->exe(); // process the program
// Destructors
delete help_object;
delete v;
// Close KH and BGI
close_KNOW_HOW();
closegraph();
}
*****************************************************************************